package com.imooc.beanannotation.jsr;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class JsrService {
	// 4.9 spring 对JSR的支持
	
	// 注解方法一 注解在成员变量上
	//@Autowired
	//@Resource
	private JsrDAO jsrDAO;
	
	// 方法二：注解在set方法上
	@Resource
	public void setJsrDAO(JsrDAO jsrDAO) {
		this.jsrDAO = jsrDAO;
	}
	

	@PostConstruct
	public void init() {
		System.out.println("JsrService init()");
	}
	@PreDestroy
	public void destroy() {
		System.out.println("JsrService destroy()");
	}
	
	public void save() {
		jsrDAO.save();
	}
	
/*//	@Resource
//	@Inject
	private JsrDAO jsrDAO;
	
//	@Resource
	@Inject
	public void setJsrDAO(@Named("jsrDAO") JsrDAO jsrDAO) {
		this.jsrDAO = jsrDAO;
	}
	
	@PostConstruct
	public void init() {
		System.out.println("JsrServie init.");
	}
	
	@PreDestroy
	public void destroy() {
		System.out.println("JsrServie destroy.");
	}

	public void save() {
		jsrDAO.save();
	}*/
	
}
